home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / tan.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  3KB  |  95 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                              N O T I C E                             *
  4.  *                                                                      *
  5.  *                      Copyright Abandoned, 1987, Fred Fish            *
  6.  *                                                                      *
  7.  *      This previously copyrighted work has been placed into the       *
  8.  *      public domain by the author (Fred Fish) and may be freely used  *
  9.  *      for any purpose, private or commercial.  I would appreciate     *
  10.  *      it, as a courtesy, if this notice is left in all copies and     *
  11.  *      derivative works.  Thank you, and enjoy...                      *
  12.  *                                                                      *
  13.  *      The author makes no warranty of any kind with respect to this   *
  14.  *      product and explicitly disclaims any implied warranties of      *
  15.  *      merchantability or fitness for any particular purpose.          *
  16.  *                                                                      *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *      tan   Double precision tangent
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *      tan
  28.  *      machine independent routines
  29.  *      trigonometric functions
  30.  *      math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *      Returns tangent of double precision floating point number.
  35.  *
  36.  *  USAGE
  37.  *
  38.  *      double tan (x)
  39.  *      double x;
  40.  *
  41.  *  INTERNALS
  42.  *
  43.  *      Computes the tangent from tan(x) = sin(x) / cos(x).
  44.  *
  45.  *      If cos(x) = 0 and sin(x) >= 0, then returns largest
  46.  *      floating point number on host machine.
  47.  *
  48.  *      If cos(x) = 0 and sin(x) < 0, then returns smallest
  49.  *      floating point number on host machine.
  50.  *
  51.  *  REFERENCES
  52.  *
  53.  *      Fortran IV plus user's guide, Digital Equipment Corp. pp. B-8
  54.  *
  55.  */
  56.  
  57. #include <stdio.h>
  58. #include <math.h>
  59. #include "pml.h"
  60.  
  61. static char funcname[] = "tan";
  62.  
  63. double 
  64. tan (x)
  65.         double x;
  66. {
  67.     double sinx;
  68.     double cosx;
  69.     struct exception xcpt;
  70.     extern double sin ();
  71.     extern double cos();
  72.  
  73.     sinx = sin (x);
  74.     cosx = cos (x);
  75.     if (cosx == 0.0) {
  76.                 xcpt.type = OVERFLOW;
  77.                 xcpt.name = funcname;
  78.                 xcpt.arg1 = x;
  79.                 if (!matherr (&xcpt)) {
  80.                         fprintf (stderr, "%s: OVERFLOW error\n", funcname);
  81.                         errno = ERANGE;
  82.                         if (sinx >= 0.0) {
  83.                                 xcpt.retval = MAXDOUBLE;
  84.                         } 
  85.                         else {
  86.                                 xcpt.retval = -MAXDOUBLE;
  87.                         }
  88.                 }
  89.     } 
  90.         else {
  91.                 xcpt.retval = sinx / cosx;
  92.     }
  93.         return( xcpt.retval );
  94. }
  95.